/**
 *	\file AKTTTLoadingTest.m
 *  
 *  \section desc_sec Description
 *  Description
 *  
 *  \if copyright
 *  	Copyright 2008 Ben Chen. All rights reserved.
 *  \endif
 *  
 *  \section hist_sec Change History:
 *  	-	2/25/08		BC		Created this file
 *  
 *  <hr>
 *  \addtogroup AKTTTTest
 *  @{
 */

#import <SenTestingKit/SenTestingKit.h>
#import "AKTTTPrincipalClass.h"
#import "AKCommon.h"
#import "AKPlayer.h"
#import "AKStateMaintainer.h"
#import "AKBasicInfoProvider.h"
#import "AKGeometryProvider.h"
#import "AKImageProvider.h"

@interface AKTTTLoadingTest : SenTestCase {
	NSString *bundlePath;
	NSBundle *bundle;
	
	id <AKPluginPrincipalClass> plugInInfo;
}

@end

@implementation AKTTTLoadingTest

- (void) setUp {
	[super setUp];
	bundlePath	= [[NSString alloc] initWithString:[[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"/AKTTT.bundle"]];
	bundle		= [NSBundle bundleWithPath:bundlePath];
	plugInInfo	= [[[bundle principalClass] alloc] init];
}

- (void) tearDown {
	[bundlePath		release];
	[bundle			release];
	[(id)plugInInfo release];
	[super tearDown];
}

- (void) testLoadingInfo {
	STAssertNotNil(bundle, @"Bundle is nil");
	
	STAssertTrue([[bundle principalClass] conformsToProtocol:@protocol(AKPluginPrincipalClass)], @"Principal class is not desired");
	
	AKTTTPrincipalClass *tttPrincipal = [[AKTTTPrincipalClass alloc] init];
	
	STAssertNotNil(plugInInfo, @"Plugin info is nil");
	
	STAssertEqualObjects([tttPrincipal playerClassNames],				[plugInInfo playerClassNames],				@"Player names not equal");
	STAssertEqualObjects([tttPrincipal stateMaintainerClassNames],		[plugInInfo stateMaintainerClassNames],		@"State maintainer names not equal");
	STAssertEqualObjects([tttPrincipal basicInfoProviderClassNames],	[plugInInfo basicInfoProviderClassNames],	@"Basin info names not equal");
	STAssertEqualObjects([tttPrincipal geometryProviderClassNames],		[plugInInfo geometryProviderClassNames],	@"Geometry provider names not equal");
	STAssertEqualObjects([tttPrincipal imageProviderClassNames],		[plugInInfo imageProviderClassNames],		@"Image provider names not equal");
}

- (void) testLoadingPlayer {
	for (NSString *playerName in [plugInInfo playerClassNames]) {
		Class playerClass = [bundle classNamed:playerName];
		STAssertNotNil(playerClass, @"%@ class is nil", playerName);
		STAssertTrue([playerClass conformsToProtocol:@protocol(AKPlayer)], @"Player:%@ doesn't conform to protocol", playerName);
	}
}

- (void) testLoadingStateMaintainer {
	for (NSString *stateMaintainer in [plugInInfo stateMaintainerClassNames]) {
		Class stateClass = [bundle classNamed:stateMaintainer];
		STAssertTrue([stateClass conformsToProtocol:@protocol(AKStateMaintainer)], @"Statemaintainer:%@ doesn't conform to protocol", stateMaintainer);
	}
}

- (void) testLoadingBasicInfoProvider {
	for (NSString *basicInfo in [plugInInfo basicInfoProviderClassNames]) {
		Class class = [bundle classNamed:basicInfo];
		STAssertTrue([class conformsToProtocol:@protocol(AKBasicInfoProvider)], @"Basic info provider:%@ doesn't conform to protocol", basicInfo);
	}
}

- (void) testLoadingGeometryProvider {
	for (NSString *geometryName in [plugInInfo geometryProviderClassNames]) {
		Class class = [bundle classNamed:geometryName];
		STAssertTrue([class conformsToProtocol:@protocol(AKGeometryProvider)], @"Geometry provider:%@ doesn't conform to protocol", geometryName);
	}
}

- (void) testLoadingImageProvider {
	for (NSString *imageProvider in [plugInInfo imageProviderClassNames]) {
		Class class = [bundle classNamed:imageProvider];
		STAssertTrue([class conformsToProtocol:@protocol(AKImageProvider)], @"Image provider:%@ doesn't conform to protocol", imageProvider);
	}
}

@end

/** @} */
